
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Model(Redux) · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="I18N.html" />
    
    
    <link rel="prev" href="LAYOUT.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="START.html">
            
                <a href="START.html">
            
                    
                    快速开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="MENU.html">
            
                <a href="MENU.html">
            
                    
                    菜单配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="PAGE.html">
            
                <a href="PAGE.html">
            
                    
                    页面开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="ROUTE.html">
            
                <a href="ROUTE.html">
            
                    
                    系统路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="AJAX.html">
            
                <a href="AJAX.html">
            
                    
                    Ajax请求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="MOCK.html">
            
                <a href="MOCK.html">
            
                    
                    Mock模拟数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="STYLE.html">
            
                <a href="STYLE.html">
            
                    
                    样式&主题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="LAYOUT.html">
            
                <a href="LAYOUT.html">
            
                    
                    导航布局
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.10" data-path="MODEL.html">
            
                <a href="MODEL.html">
            
                    
                    Model(Redux)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="I18N.html">
            
                <a href="I18N.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="PERMISSION.html">
            
                <a href="PERMISSION.html">
            
                    
                    权限控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="NGINX.html">
            
                <a href="NGINX.html">
            
                    
                    Nginx配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="PROXY.html">
            
                <a href="PROXY.html">
            
                    
                    开发代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="OTHER.html">
            
                <a href="OTHER.html">
            
                    
                    其他
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Model(Redux)</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="modelsredux-&#x5C01;&#x88C5;">models(redux) &#x5C01;&#x88C5;</h1>
<p>&#x57FA;&#x4E8E;<a href="https://redux.js.org/" target="_blank">redux</a>&#x8FDB;&#x884C;&#x5C01;&#x88C5;&#xFF0C;&#x4E0D;&#x6539;&#x53D8;redux&#x6E90;&#x7801;&#xFF0C;&#x53EF;&#x4EE5;&#x7ED3;&#x5408;&#x4F7F;&#x7528;redux&#x793E;&#x533A;&#x4E2D;&#x5176;&#x4ED6;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;</p>
<h2 id="models&#x7528;&#x4E8E;&#x7BA1;&#x7406;&#x6570;&#x636E;&#xFF0C;&#x89E3;&#x51B3;&#x7684;&#x95EE;&#x9898;&#xFF1A;">models&#x7528;&#x4E8E;&#x7BA1;&#x7406;&#x6570;&#x636E;&#xFF0C;&#x89E3;&#x51B3;&#x7684;&#x95EE;&#x9898;&#xFF1A;</h2>
<ol>
<li>&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF08;&#x9632;&#x6B62;&#x6570;&#x636E;&#x3001;&#x65B9;&#x6CD5;&#x547D;&#x540D;&#x51B2;&#x7A81;&#xFF09;&#xFF1A;&#x6570;&#x636E;&#x4E0E;&#x65B9;&#x6CD5;&#xFF0C;&#x90FD;&#x5F52;&#x5C5E;&#x4E8E;&#x5177;&#x4F53;model&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;state.userCenter.xxx&#xFF0C;this.props.action.userCenter.xxx();</li>
<li>&#x5982;&#x4F55;&#x65B9;&#x4FBF;&#x7684;&#x83B7;&#x53D6;&#x6570;&#x636E;&#xFF1A;connect&#x4E0E;&#x7EC4;&#x4EF6;&#x8FDE;&#x63A5;&#xFF1B;@connect(state =&gt; ({name: state.user.name}));</li>
<li>&#x5982;&#x4F55;&#x65B9;&#x4FBF;&#x7684;&#x4FEE;&#x6539;&#x6570;&#x636E;&#xFF1A;this.props.action&#x4E2D;&#x65B9;&#x6CD5;&#xFF1B;</li>
<li>&#x5BA2;&#x6237;&#x7AEF;&#x6570;&#x636E;&#x6301;&#x4E45;&#x5316;&#xFF08;&#x4FDD;&#x5B58;&#x5230;LocalStorage&#x4E2D;&#xFF09;&#xFF1A;syncStorage&#x914D;&#x7F6E;&#xFF1B;</li>
<li>&#x5F02;&#x6B65;&#x6570;&#x636E;&#x5904;&#x7406;&#xFF1A;&#x57FA;&#x4E8E;promise&#x5F02;&#x6B65;&#x5C01;&#x88C5;&#xFF1B;</li>
<li>&#x8BF7;&#x6C42;&#x9519;&#x8BEF;&#x63D0;&#x793A;&#xFF1A;error&#x5904;&#x7406;&#x5C01;&#x88C5;&#xFF0C;errorTip&#x914D;&#x7F6E;&#xFF0C;&#x81EA;&#x52A8;&#x63D0;&#x793A;&#xFF1B;</li>
<li>&#x8BF7;&#x6C42;&#x6210;&#x529F;&#x63D0;&#x793A;&#xFF1A;successTip&#x914D;&#x7F6E;&#xFF0C;&#x81EA;&#x52A8;&#x63D0;&#x793A;&#xFF1B;</li>
<li>&#x7B80;&#x5316;&#x5199;&#x6CD5;&#xFF1A;types actions reducers &#x53EF;&#x4EE5;&#x5728;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x4E2D;&#x7F16;&#x5199;&#xFF0C;&#x8F83;&#x5C11;&#x51B2;&#x7A81;&#xFF0C;&#x65B9;&#x4FBF;&#x591A;&#x4EBA;&#x534F;&#x4F5C;&#xFF0C;&#x53C2;&#x89C1;<a href="page.js"><code>models/page.js</code></a>&#x4E2D;&#x7684;&#x5199;&#x6CD5;;</li>
<li>&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x53EF;&#x96C6;&#x4E2D;&#x5F52;&#x7C7B;&#xFF1A;&#x5728;models&#x76EE;&#x5F55;&#x4E2D;&#x7EDF;&#x4E00;&#x7F16;&#x5199;&#xFF0C;&#x6216;&#x8005;&#x5728;&#x5177;&#x4F53;&#x4E1A;&#x52A1;&#x76EE;&#x5F55;&#x4E2D;&#xFF0C;&#x6A21;&#x5757;&#x5316;&#x65B9;&#x5F0F;&#x3002;</li>
</ol>
<h2 id="all-modelsjs">all-models.js</h2>
<p>&#x6B64;&#x6587;&#x4EF6;&#x901A;&#x8FC7;&#x811A;&#x672C;&#x81EA;&#x52A8;&#x751F;&#x6210;&#xFF0C;&#x4E0D;&#x8981;&#x76F4;&#x63A5;&#x7F16;&#x8F91;&#xFF0C;&#x751F;&#x6210;&#x89C4;&#x5219;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code>/path/to/models/user-center.js --&gt; export userCenter from &apos;/path/to/models/user-center&apos;;
/path/to/user-center.model.js  --&gt; export userCenter from &apos;/path/to/user-center.model.js&apos;;
/path/to/user-center/model.js  --&gt; export userCenter from &apos;/path/to/user-center/model.js&apos;;
</code></pre><h2 id="&#x7EC4;&#x4EF6;&#x4E0E;redux&#x8FDB;&#x884C;&#x8FDE;&#x63A5;">&#x7EC4;&#x4EF6;&#x4E0E;redux&#x8FDB;&#x884C;&#x8FDE;&#x63A5;</h2>
<p>&#x63D0;&#x4F9B;&#x4E86;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x88C5;&#x9970;&#x5668;&#x65B9;&#x5F0F;&#x3001;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#xFF1B;</p>
<h3 id="&#x88C5;&#x9970;&#x5668;">&#x88C5;&#x9970;&#x5668;</h3>
<p>&#x63A8;&#x8350;&#x4F7F;&#x7528;&#x88C5;&#x9970;&#x5668;&#x65B9;&#x5F0F;</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> {connect} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;path/to/models&apos;</span>;

@connect(state =&gt; {
    <span class="hljs-keyword">return</span> {
        ...
    }
})
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Demo</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span></span>{
    ...
}
</code></pre>
<h3 id="&#x51FD;&#x6570;">&#x51FD;&#x6570;</h3>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> {connectComponent} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;path/to/models&apos;</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Demo</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Component</span> </span>{
   ... 
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapStateToProps</span>(<span class="hljs-params">state</span>) </span>{
    <span class="hljs-keyword">return</span> {
        ...
    };
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> connectComponent({LayoutComponent: Demo, mapStateToProps});
</code></pre>
<h2 id="&#x7B80;&#x5316;&#x5199;&#x6CD5;">&#x7B80;&#x5316;&#x5199;&#x6CD5;</h2>
<p>action reducer &#x4E8C;&#x5408;&#x4E00;&#xFF0C;&#x7701;&#x53BB;&#x4E86;actionType&#xFF0C;&#x7B80;&#x5316;&#x5199;&#x6CD5;&#xFF1B;</p>
<p>&#x6CE8;&#x610F;&#xFF1A;</p>
<ul>
<li>&#x6240;&#x6709;&#x7684;reducer&#x65B9;&#x6CD5;&#xFF0C;&#x65E0;&#x8BBA;&#x662F;&#x4EC0;&#x4E48;&#x5199;&#x6CD5;&#x4E2D;&#x7684;&#xFF0C;&#x90FD;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x5FC5;&#x5173;&#x5FC3;&#x4E0E;&#x539F;&#x6570;&#x636E;&#x5408;&#x5E76;&#xFF08;...state&#xFF09;&#xFF0C;&#x5C01;&#x88C5;&#x5185;&#x90E8;&#x505A;&#x4E86;&#x5408;&#x5E76;&#xFF1B;</li>
<li>&#x4E00;&#x4E2A;model&#x4E2D;&#xFF0C;&#x9664;&#x4E86;initialState syncStorage actions reducers &#x7B49;&#x5173;&#x952E;&#x5B57;&#x4E4B;&#x5916;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x90FD;&#x89C6;&#x4E3A;action reducer&#x5408;&#x5E76;&#x5199;&#x6CD5;;</li>
</ul>
<h3 id="&#x4E00;&#x4E2A;&#x51FD;&#x6570;">&#x4E00;&#x4E2A;&#x51FD;&#x6570;</h3>
<p>&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x5373;&#x53EF;&#x4F5C;&#x4E3A;action&#x65B9;&#x6CD5;&#xFF0C;&#x4E5F;&#x4F5C;&#x4E3A;reduce&#x4F7F;&#x7528;</p>
<ul>
<li>&#x8C03;&#x7528;action&#x65B9;&#x6CD5;&#x4F20;&#x9012;&#x7684;&#x6570;&#x636E;&#x5C06;&#x4E0D;&#x4F1A;&#x505A;&#x4EFB;&#x4F55;&#x5904;&#x7406;&#xFF0C;&#x4F1A;&#x76F4;&#x63A5;&#x4F20;&#x9012;&#x7ED9; reducer</li>
<li>&#x53EA;&#x80FD;&#x7528;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x63A5;&#x6536;&#x4F20;&#x9012;&#x8FC7;&#x6765;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5982;&#x679C;&#x591A;&#x4E2A;&#x6570;&#x636E;&#xFF0C;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x5BF9;&#x8C61;&#x65B9;&#x5F0F;&#x4F20;&#x9012;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x9700;&#x8981;&#x4F20;&#x9012;&#x6570;&#x636E;&#xFF0C;&#x4F46;&#x662F;&#x8981;&#x4F7F;&#x7528;state&#xFF0C;&#x4E5F;&#x9700;&#x8981;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x5360;&#x4F4D;</li>
<li>&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x56FA;&#x5B9A;&#x4E3A;state&#xFF0C;&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x56FA;&#x5B9A;&#x4E3A;action&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x53EF;&#x4EE5;&#x7F3A;&#x7701;&#xFF08;&#x4E00;&#x822C;&#x90FD;&#x662F;&#x7F3A;&#x7701;&#x7684;&#xFF09;</li>
<li>&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6216;&#x8005;undefined&#xFF0C;&#x5C06;&#x4E8E;&#x539F;state&#x5408;&#x5E76;&#xFF0C;&#x4F5C;&#x4E3A;store&#x65B0;&#x7684;state</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// page.model.js</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    initialState: {
        title: <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>,
        name: <span class="hljs-keyword">void</span> <span class="hljs-number">0</span>,
        user: {},
        toggle: <span class="hljs-literal">true</span>,
    },

    setTitle: title =&gt; ({title}),
    setName: (name, state, action) =&gt; {
        <span class="hljs-keyword">const</span> {name: prevName} = state;
        <span class="hljs-keyword">if</span>(name !== prevName) <span class="hljs-keyword">return</span> {name: <span class="hljs-string">&apos;Different Name&apos;</span>};
    },
    setUser: ({name, age} = {}) =&gt; ({user: {name, age}}),
    setToggle: (arg, state) =&gt; ({toggle: !state.toggle}),
}

<span class="hljs-comment">// &#x4F7F;&#x7528;</span>
<span class="hljs-keyword">this</span>.props.action.page.setTitle(<span class="hljs-string">&apos;my title&apos;</span>);
</code></pre>
<h3 id="&#x6570;&#x636E;&#x540C;&#x6B65;">&#x6570;&#x636E;&#x540C;&#x6B65;</h3>
<p>&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;redux&#x4E2D;&#x7684;&#x6570;&#x636E;&#x81EA;&#x52A8;&#x4E0E;localStorage&#x540C;&#x6B65;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    initialState: {
        title: <span class="hljs-string">&apos;&apos;</span>,
        show: <span class="hljs-literal">true</span>,
        user: {},
        users: [], 
        job: {},
        total: <span class="hljs-number">0</span>,
        loading: <span class="hljs-literal">false</span>,
        ...
    },

    <span class="hljs-comment">// initialState&#x4F1A;&#x5168;&#x90E8;&#x540C;&#x6B65;&#x5230;localStorage&#x4E2D;</span>
    <span class="hljs-comment">// syncStorage: true,</span>

    <span class="hljs-comment">// &#x914D;&#x7F6E;&#x90E8;&#x5206;&#x5B58;&#x6570;&#x636E;&#x50A8;&#x5230;localStorage&#x4E2D; </span>
    syncStorage: { 
        titel: <span class="hljs-literal">true</span>,
        user: { <span class="hljs-comment">// &#x652F;&#x6301;&#x5BF9;&#x8C61;&#x6307;&#x5B9A;&#x5B57;&#x6BB5;&#xFF0C;&#x4EFB;&#x610F;&#x5C42;&#x6B21;</span>
            name: <span class="hljs-literal">true</span>,
            address: {
                city: <span class="hljs-literal">true</span>,
            },
        },
        job: <span class="hljs-literal">true</span>,
        users: [{name: <span class="hljs-literal">true</span>, age: <span class="hljs-literal">true</span>}], <span class="hljs-comment">// &#x652F;&#x6301;&#x6570;&#x7EC4;</span>
    },
}
</code></pre>
<h3 id="action-reducer-&#x5408;&#x5E76;&#x5199;&#x6CD5;">action reducer &#x5408;&#x5E76;&#x5199;&#x6CD5;</h3>
<p>&#x5982;&#x679C;action&#x6709;&#x989D;&#x5916;&#x7684;&#x6570;&#x636E;&#x5904;&#x7406;&#xFF0C;&#x5E76;&#x4E14;&#x4E00;&#x4E2A;action &#x53EA;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;reducer&#xFF0C;&#x8FD9;&#x79CD;&#x5199;&#x6CD5;&#x4E0D;&#x9700;&#x8981;&#x6307;&#x5B9A;actionType&#xFF0C;&#x53EF;&#x4EE5;&#x6709;&#x6548;&#x7B80;&#x5316;&#x4EE3;&#x7801;&#xFF1B;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    initialState: {
        title: <span class="hljs-string">&apos;&apos;</span>,
        ...
    },

    arDemo: {
        <span class="hljs-comment">// &#x5982;&#x679C;&#x662F;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x503C;&#x5C06;&#x4F5C;&#x4E3A;action.payload &#x4F20;&#x9012;&#x7ED9;reducer&#xFF0C;&#x5982;&#x679C;&#x975E;&#x51FD;&#x6570;&#xFF0C;&#x76F4;&#x63A5;&#x5C06;payload&#x7684;&#x503C;&#xFF0C;&#x4F5C;&#x4E3A;action.payload;</span>
        payload(options) {...},

        <span class="hljs-comment">// &#x5982;&#x679C;&#x662F;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x503C;&#x5C06;&#x4F5C;&#x4E3A;action.meta &#x4F20;&#x9012;&#x7ED9;reducer&#xFF0C;&#x5982;&#x679C;&#x975E;&#x51FD;&#x6570;&#xFF0C;&#x76F4;&#x63A5;&#x5C06;meta&#x7684;&#x503C;&#xFF0C;&#x4F5C;&#x4E3A;action.meta;</span>
        meta(options) {...},
        reducer(state, action) {
            returtn {...newState}; <span class="hljs-comment">// &#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#x8981;&#x4FEE;&#x6539;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5185;&#x90E8;&#x5C01;&#x88C5;&#x4F1A;&#x4E0E;&#x539F;state&#x5408;&#x5E76;`{...state, ...newState}`;</span>
        },
    },
};
</code></pre>
<h3 id="&#x5F02;&#x6B65;action&#x5199;&#x6CD5;">&#x5F02;&#x6B65;action&#x5199;&#x6CD5;</h3>
<pre><code class="lang-js">
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    initialState: {
        title: <span class="hljs-string">&apos;&apos;</span>,
        ...
    },
    fetchUser: {
        <span class="hljs-comment">// &#x5F02;&#x6B65;action payload &#x8FD4;&#x56DE;promise     </span>
        payload: ({params, options}) =&gt; axios.get(<span class="hljs-string">&apos;/mock/users&apos;</span>, params, options),

        <span class="hljs-comment">// &#x5F02;&#x6B65;action &#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x901A;&#x7528;&#x5F02;&#x6B65;meta&#x914D;&#x7F6E; commonAsyncMeta&#xFF0C;&#x5BF9;successTip errorTip onResolve onReject onComplete &#x8FDB;&#x884C;&#x4E86;&#x5408;&#x7406;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x5904;&#x7406;&#xFF0C;&#x9700;&#x8981;action&#x4EE5;&#x5BF9;&#x8C61;&#x5F62;&#x5F0F;&#x4F20;&#x53C2;&#x8C03;&#x7528;</span>
        <span class="hljs-comment">// meta: commonAsyncMeta, </span>
        <span class="hljs-comment">// meta: {</span>
        <span class="hljs-comment">//     successTip: &apos;&#x67E5;&#x8BE2;&#x6210;&#x529F;&#xFF01;&#x6B27;&#x8036;~&apos;,</span>
        <span class="hljs-comment">//     errorTip: &apos;&#x81EA;&#x5B9A;&#x4E49;errorTip&#xFF01;&#x9A6C;&#x4E39;~&apos;,</span>
        <span class="hljs-comment">// },</span>
        <span class="hljs-comment">// meta: () =&gt; {</span>
        <span class="hljs-comment">//    return {...};</span>
        <span class="hljs-comment">// },</span>

        <span class="hljs-comment">// &#x57FA;&#x4E8E;promise &#x5F02;&#x6B65;reducer&#x5199;&#x6CD5;&#xFF1B;</span>
        reducer: {
            pending: (state, action) =&gt; ({loading: <span class="hljs-literal">true</span>}),
            resolve(state, {payload = {}}) {
                <span class="hljs-keyword">const</span> {total = <span class="hljs-number">0</span>, list = []} = payload;
                <span class="hljs-keyword">return</span> {
                    users: list,
                    total,
                }
            },
            complete: (state, action) =&gt; ({loading: <span class="hljs-literal">false</span>}),
        }
    },
};
</code></pre>
<p>&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">this</span>.props.action.user
    .fetchUser({
        params, 
        options, 
        successTip, 
        errorTip,
        onResolve, 
        onReject, 
        onComplete
    });
</code></pre>
<p>&#x53C2;&#x6570;&#x7EA6;&#x5B9A;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x5404;&#x4E2A;&#x5C5E;&#x6027;&#x8BF4;&#x660E;&#x5982;&#x4E0B;:</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>params</td>
<td>&#x8BF7;&#x6C42;&#x53C2;&#x6570;</td>
</tr>
<tr>
<td>options</td>
<td>&#x8BF7;&#x6C42;&#x914D;&#x7F6E;</td>
</tr>
<tr>
<td>successTip</td>
<td>&#x6210;&#x529F;&#x63D0;&#x793A;&#x4FE1;&#x606F;</td>
</tr>
<tr>
<td>errorTip</td>
<td>&#x9519;&#x8BEF;&#x63D0;&#x793A;&#x4FE1;&#x606F;</td>
</tr>
<tr>
<td>onResolve</td>
<td>&#x6210;&#x529F;&#x56DE;&#x8C03;</td>
</tr>
<tr>
<td>onReject</td>
<td>&#x5931;&#x8D25;&#x56DE;&#x8C03;</td>
</tr>
<tr>
<td>onComplete</td>
<td>&#x5B8C;&#x6210;&#x56DE;&#x8C03;&#xFF0C;&#x65E0;&#x8BBA;&#x6210;&#x529F;&#x3001;&#x5931;&#x8D25;&#x90FD;&#x4F1A;&#x8C03;&#x7528;</td>
</tr>
</tbody>
</table>
<h3 id="&#x5355;&#x72EC;&#x5B9A;&#x4E49;action-&#x548C;-reducer">&#x5355;&#x72EC;&#x5B9A;&#x4E49;action &#x548C; reducer</h3>
<p>&#x652F;&#x6301;&#x8FD9;&#x79CD;&#x6BD4;&#x8F83;&#x4F20;&#x7EDF;&#x7684;&#x5199;&#x6CD5;&#xFF0C;&#x4E00;&#x822C;&#x4E5F;&#x4E0D;&#x4F1A;&#x592A;&#x7528;&#x5230;</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> {createAction} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;redux-actions&apos;</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> types = {
    GET_MENU_STATUS: <span class="hljs-string">&apos;MENU:GET_MENU_STATUS&apos;</span>, <span class="hljs-comment">// &#x9632;&#x6B62;&#x5404;&#x4E2A;&#x6A21;&#x5757;&#x51B2;&#x7A81;&#xFF0C;&#x6700;&#x597D;&#x6A21;&#x5757;&#x540D;&#x5F00;&#x5934;</span>
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    initialState: {
        title: <span class="hljs-string">&apos;&apos;</span>,
        ...
    },

    <span class="hljs-comment">// &#x5355;&#x72EC;action&#x5B9A;&#x4E49;&#xFF0C;&#x9700;&#x8981;&#x4F7F;&#x7528;actionType&#x4E0E;reducer&#x8FDB;&#x884C;&#x5173;&#x8054;</span>
    actions: {
        getMenuStatus: createAction(types.GET_MENU_STATUS),
    },

    <span class="hljs-comment">// &#x5355;&#x72EC;reducer&#x5B9A;&#x4E49;&#xFF0C;&#x4F7F;&#x7528;&#x4E86;actionType&#xFF0C;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x5904;&#x7406;&#x5F53;&#x524D;model&#x4E2D;&#x7684;action</span>
    <span class="hljs-comment">// &#x4E5F;&#x53EF;&#x4EE5;&#x5904;&#x7406;&#x5176;&#x4ED6;&#x4EFB;&#x610F;action&#xFF08;&#x53EA;&#x8981;actionType&#x80FD;&#x5BF9;&#x5E94;&#xFF09;</span>
    reducers: {
        [types.GET_MENU_STATUS](state) {
            ...
            return {
                ...
            };
        }
    },
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="LAYOUT.html" class="navigation navigation-prev " aria-label="Previous page: 导航布局">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="I18N.html" class="navigation navigation-next " aria-label="Next page: 国际化">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Model(Redux)","level":"1.10","depth":1,"next":{"title":"国际化","level":"1.11","depth":1,"path":"I18N.md","ref":"I18N.md","articles":[]},"previous":{"title":"导航布局","level":"1.9","depth":1,"path":"LAYOUT.md","ref":"LAYOUT.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"MODEL.md","mtime":"2019-02-16T09:08:05.324Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-17T03:27:10.809Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

